﻿@model System.Linq.IQueryable
@using System.Web.UI.WebControls
@using DistanceLearning.Controllers
@using PivotCustomGroupIntervalEventArgs = DevExpress.Web.ASPxPivotGrid.PivotCustomGroupIntervalEventArgs

<script type="text/javascript">
    var rowIndex;
    var columnIndex;

    function OnCloseDrillDownPopup(s, e) {
        rowIndex = null;
        columnIndex = null;
        journalPivotGrid.PerformCallback({ "SubjectName": subjectsComboBox.lastSuccessValue }); // Refresh grid
    }
    function OnPivotGridCellClick(s, e) {
        rowIndex = e.RowIndex;
        columnIndex = e.ColumnIndex;
        
        drillDownGridView.PerformCallback({ "IsResetGridViewPageIndex": true });
        ShowDrillDownPopup();
    }
    function OnGridViewBeginCallback(s, e) {
        debugger;
        e.customArgs["SubjectName"] = subjectsComboBox.lastSuccessValue;
        e.customArgs["RowIndex"] = rowIndex;
        e.customArgs["ColumnIndex"] = columnIndex;
        journalPivotGrid.FillStateObject(e.customArgs);
    }
    function OnGridViewEndCallback(s, e) {
        drillDownPopup.SetSize(100, 100);
        //journalPivotGrid.PerformCallback({ "SubjectName": subjectsComboBox.lastSuccessValue });
    }
    function ShowDrillDownPopup() {
        var mainElement = journalPivotGrid.GetMainElement();
        drillDownPopup.ShowAtPos(ASPxClientUtils.GetAbsoluteX(mainElement), ASPxClientUtils.GetAbsoluteY(mainElement));
    }

    function OnComboBoxSelectedIndexChanged(s, e) {
        journalPivotGrid.PerformCallback({ "SubjectName": subjectsComboBox.lastSuccessValue });
    }
    
    function OnJournalGridBeginCallback(s, e) {
        debugger;
        e.customArgs["SubjectName"] = subjectsComboBox.lastSuccessValue;
        journalPivotGrid.FillStateObject(e.customArgs);
    }
</script>

<script type="text/javascript">
    function OnExport() {
       // SetFormAction(true);
        $("form").submit();
       // SetFormAction(false);
    }
    @*function SetFormAction(isExportAction) {
        var routeUrl = '@Url.Action(string.Empty, "PivotGrid")';
        $("form").attr("action", routeUrl + (isExportAction ? "/ExportTo" : "/Export"));
    }*@
</script>

@using (Html.BeginForm("Export", "Journal")) {
    //PivotGridExportDemoOptions options = (PivotGridExportDemoOptions)Session["ExportOptions"];
    
    <div style="height: 140px;">
        <div>
            <strong>Export to:</strong>&nbsp;

            @Html.DropDownList("ExportType", new List<SelectListItem>{new SelectListItem {Selected = true, Value= "Excel", Text = "Excel"}})
            <input type="button" value="Save" onclick="OnExport()"/>
        </div>
    </div>
    <br />
}

@Html.DevExpress().ComboBox(
     settings => {
         settings.Name = "subjectsComboBox";
         settings.Width = 180;
         settings.SelectedIndex = 0;
         settings.Properties.IncrementalFilteringMode = IncrementalFilteringMode.StartsWith;
         settings.Properties.DropDownStyle = DropDownStyle.DropDown;
         settings.Properties.TextField = "SubjectName";
         settings.Properties.ValueField = "SubjectName";
         settings.Properties.ClientSideEvents.SelectedIndexChanged = "OnComboBoxSelectedIndexChanged";
     }).BindList(ViewData["Subjects"]).GetHtml()


    @Html.Partial("JournalPagePartial", Model)

@Html.DevExpress().PopupControl(
    settings => {
        settings.Name = "drillDownPopup";
        settings.Modal = true;
        settings.AllowDragging = true;
        settings.Left = 200;
        settings.Top = 200;
        settings.HeaderText = "Заполнение оценок";
        settings.ClientSideEvents.Closing = "OnCloseDrillDownPopup";

        settings.SetContent(() => {
            Html.RenderAction("GridViewPartial");
        });
    }).GetHtml()